
$(function() {
    var module = {};
    var tools = Tools();
    var subObj = {1: "充值", 2: "手机快捷支付充值收入", 3: "投资",
        4: "放款收入", 5: "提现", 6: "冻结", 7:"解冻" ,
        8: "冻结支出" ,9:"手续费支出 " ,11: "归还本金" ,
        12:"本金回款",13:"支付利息", 14:"利息回款",15:"管理员充值",
        16:"日薪宝转入",20:"充值再日薪宝转入",17:"日薪宝转出",
        18:"日薪宝收益",19:"日薪宝转出再提现", 21:"平台活动奖励",
        22:"转出到定活宝", 23:"定活宝转入"};

    module.init=function () {
        tools.getUserInfo();
        tools.isOpenAccount();
        $('.INCOME_a').on('click',function () {
            $('#investA').show();
            $('#investB').hide();
            $('#investC').hide();
            module.initData('cz','pager',false,tools.apiURL.rechargeLog);
            $('.OUTLAY_h').removeClass('curr');
            $('.ALL_h').removeClass('curr');
            $('.INCOME_h').addClass('curr');
        });
        $('.OUTLAY_a').on('click',function () {
            $('#investA').hide();
            $('#investB').show();
            $('#investC').hide();
            module.initData('tx','pager1',false,tools.apiURL.withdrawLog);
            $('.INCOME_h').removeClass('curr');
            $('.ALL_h').removeClass('curr');
            $('.OUTLAY_h').addClass('curr');
        });
        $('.ALL_a').on('click',function () {
            $('#investA').hide();
            $('#investB').hide();
            $('#investC').show();
            module.initData('ls','pager2',false,tools.apiURL.queryFundPage,'capital');
            $('.INCOME_h').removeClass('curr');
            $('.OUTLAY_h').removeClass('curr');
            $('.ALL_h').addClass('curr');
        });

        $('#investB').hide();
        $('#investC').hide();
        module.initData('cz','pager',true,tools.apiURL.rechargeLog);

    };

    module.initData=function (types,pages,tag,urls,flag) {
        //充值记录
        $('#'+pages).sjAjaxPager({
            url: accountURL+urls,
            pageSize: 10,
            type :'GET',
            orderField:'gmtCreated',
            orderDirection:'desc',
            searchParam: {
                type : 1,
                status:types,
                pageStart:tag,
                queryFlag:flag
            },
            crossDomain: true,
            xhrFields: {
                withCredentials: true
            },
            beforeSend: function(xhr) {

            },
            success: function (data) {
                var content = data.data.data;
                var list = '',
                    page = '';
                if(content && content.length){
                    list += $.map(content,function(value,len){
                        var o_starts;
                        var zt='';
                        if(types=='cz'){
                            zt='充值'
                        }else{
                            zt='提现'
                        }
                        if(value.status==1){
                            o_starts='正在'+zt+'中';
                        }else  if(value.status==2){
                            o_starts=zt+'成功';
                        }else if(value.status==0){
                            o_starts='创建订单';
                        }else{
                            o_starts=zt+'失败';
                        }
                        if(value.notice==null||value.notice==undefined){
                            value.notice='';
                        }

                        if(types=='cz'){
                            return '<tr><td>'+value.gmtCreated+'</td><td>'+value.payOrderNo+'</td> <td>'+value.amount+'元</td> <td> '+o_starts+' </td><td>'+value.notice+'</td> </tr>'
                        }else if(types=='tx'){
                            var o_types;
                            if(value.deviceType==1){
                                o_types='网站(PC)'
                            }else  if(value.deviceType==2){
                                o_types='IOS'
                            }else  if(value.deviceType==3){
                                o_types='Android'
                            }else{
                                o_types='微信'
                            }
                            return '<tr><td>'+value.gmtCreated+'</td><td>'+value.payOrderNo+'</td> <td>'+value.amount+'元</td> <td> '+o_starts+' </td><td>来自 '+o_types+'</td><td>'+value.notice+'</td> </tr>'
                        }else{

                            if(value.income==null||value.income==undefined){
                                value.income='';
                            }else{
                                value.income=value.income+'元';
                            }
                            if(value.outlay==null||value.outlay==undefined){
                                value.outlay='';
                            }else{
                                value.outlay=value.outlay+'元';
                            }

                            return '<tr><td>'+value.gmtCreated+'</td><td>'+subObj[value.subject]+'</td> <td>'+value.income+'</td> <td> '+value.outlay+'</td><td>'+value.balance+'元</td><td>'+value.notice+'</td> </tr>'

                        }

                    }).join('');
                    $('#'+pages).show();
                }else{
                    $('#'+pages).hide();
                    list += '<tr class="noList"><td colspan="6" align="center" style="text-align: center">暂无记录</tr>';
                }
                if(types=="cz"){
                    $('.investList tbody').empty().append(list);

                }else if(types=='tx'){
                    $('.investList1 tbody').empty().append(list);
                }else{
                    $('.investList2 tbody').empty().append(list);
                }
            },
            complete: function () {
            }
        });
    };


    module.init();
});